/*
 * ParamByte.java
 * 
 * Copyright 2004 Christoph Csallner and Yannis Smaragdakis.
 */
package edu.gatech.cc.cnc.params;

import de.fhg.first.fd.X;
import edu.gatech.cc.jcrasher.plans.expr.Expression;
import edu.gatech.cc.jcrasher.plans.expr.literals.ByteLiteral;

/**
 * Represents a byte variable / method parameter.
 * 
 * @author csallner@gatech.edu (Christoph Csallner)
 */
public class ParamByte extends ParamIntegral<Byte> {

	/**
	 * Constructor
	 */
	public ParamByte(String name) {
		super(Byte.MIN_VALUE, Byte.MAX_VALUE, name, byteDomain);
	}

	
	/**
	 * @return variable (!= null) iff constant in domain.
	 */
	@Override
	public X parse(String constant) {
		int i;
		
		try {
			i = Byte.parseByte(constant);}
		catch (NumberFormatException e) {
			return parseError(constant);
		}
		
		return solver.newX(i);
	}

	
	/**
	 * Assumes that constraint system solution to which var belongs has been
	 * first prepared and then generated before.
	 */	
	@Override
	public Expression<Byte> getPlanExpression() {
		return new ByteLiteral((byte)getValue());
	}
	
	@Override
	public Class<Byte> getType() {
		return Byte.TYPE;
	}

}
